package packag04;

import com.ynny.bean.Score;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

@Component
public class ScoreDapImpl implements ScoreDao {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    @Override
    public void addScore(Score score) {
        String sql = "insert into score(chinese,math,english) values(?,?,?)";
        int i = jdbcTemplate.update(sql,score.getChinese(),score.getMath(),score.getEnglish());
        if(i>0){
            System.out.println("添加成功");
        }else{
            System.out.println("添加失败");
        }

    }

    @Override
    public void updateScore(Integer id, Double chinese, Double math, Double english) {
        String sql = "update score set chinese=?,math=?,english=? where id=?";
        int i = jdbcTemplate.update(sql,chinese,math,english,id);
        if(i>0){
            System.out.println("修改成功");
        }else{
            System.out.println("修改失败");
        }

    }

    @Override
    public void queryScore(Integer id) {
        String sql = "select * from score where id=?";
        Score score = jdbcTemplate.queryForObject(sql,new Object[]{id},new BeanPropertyRowMapper<Score>(Score.class));
        System.out.println(score);

    }

    @Override
    public void queryAllScore(int i) {

    }
}